package com.ruoyi.workbench.utils;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.workbench.constants.Constant;
import com.ruoyi.workbench.domain.WbVisitLog;

import java.util.Date;
import java.util.Objects;

/**
 * @author hanjiafeng
 * @date 2021/3/23 19:58
 * @desc todo
 */
public class Checker {

    /**
     * 检查用户输入的信息是否符合标准
     *
     * @param wbVisitLog 用户信息
     * @return 结果
     */
    public static AjaxResult checkUserCommit(WbVisitLog wbVisitLog) {
        String userName = wbVisitLog.getUserName();
        String currentPhoneNumber = wbVisitLog.getCurrentPhoneNumber();
        Long communicationOperator = wbVisitLog.getCommunicationOperator();
        Long mealValue = wbVisitLog.getMealValue();
        Date expiredTime = wbVisitLog.getExpiredTime();
        String scenePhoto = wbVisitLog.getScenePhoto();
        if (StringUtils.isEmpty(userName)
                || StringUtils.isEmpty(currentPhoneNumber) || Objects.isNull(communicationOperator)
                || Objects.isNull(mealValue) || StringUtils.isEmpty(scenePhoto)) {
            return AjaxResult.error("请检查必填项");
        }
        String[] scenePhotoArray = scenePhoto.split(",");
        if (scenePhotoArray.length > Constant.MAX_IMAGE_COUNT) {
            return AjaxResult.error("图片最多上传" + Constant.MAX_IMAGE_COUNT + "张");
        }
        if (communicationOperator.equals(Constant.OTHER_NET_USER) && Objects.isNull(expiredTime)) {
            return AjaxResult.error("异网用户过期时间必填");
        }

        if (!Objects.isNull(expiredTime) && expiredTime.before(new Date())) {
            return AjaxResult.error("过期时间不能早于今天");
        }
        return AjaxResult.success();
    }
}
